﻿/*
 * Created by SharpDevelop.
 * User: Carlos
 * Date: 27/05/2009
 * Time: 10:47 p.m.
 */
namespace Lambda.Data.NetQuery {
    /// <summary>
    /// BaseCondition. Representa una condición
    /// </summary>
    public abstract class BaseCondition
    {
        #region Fields && Properties
            public virtual ConditionTypes ConditionType {
                get { return ConditionTypes.Single; }
            }
        #endregion
    }
    /// <summary>
    /// SingleCondition. Condicion sencilla
    /// </summary>
    public class Condition : BaseCondition
    {
        #region Fields && Properties
            private SingleConditionTypes type;
            private BaseConditionElement leftElement;
            private BaseConditionElement rightElement;
            public SingleConditionTypes Type{
                get { return type; }
            }
            public BaseConditionElement LeftElement{
                get { return leftElement; }
                set { leftElement = value; }
            }
            public BaseConditionElement RightElement{
                get { return rightElement; }
                set { rightElement = value; }
            }
        #endregion
        #region Constructors
            public Condition(){
                type = SingleConditionTypes.Equal;
            }
            public Condition(SingleConditionTypes Type){
                type = Type;
            }
            public Condition(BaseConditionElement LeftElement, BaseConditionElement RightElement): this(){
                leftElement = LeftElement;
                rightElement = RightElement;
            }
            public Condition(SingleConditionTypes Type, BaseConditionElement LeftElement, BaseConditionElement RightElement): this(Type){
                leftElement = LeftElement;
                rightElement = RightElement;
            }
        #endregion
        #region Base Implementation
            public new ConditionTypes ConditionType{
                get { return ConditionTypes.Single; }
            }
        #endregion
    }
    /// <summary>
    /// MultipleCondition. Condicion multiple
    /// </summary>
    public class MultipleCondition : BaseCondition
    {
        #region Fields && Properties
            private MultipleConditionTypes type;
            public MultipleConditionTypes Type {
                get { return type; }
            }
            private ConditionList conditions;
            public bool HasConditions {
                get{
                    if (conditions == null){
                        return false;
                    }else if (conditions.Count == 0){
                        return false;
                    }
                    else{
                        return true;
                    }
                }
            }
            public ConditionList Conditions { 
                get{
                    if (conditions == null){
                        conditions = new ConditionList();
                    }
                    return conditions;
                }
            }
        #endregion
        #region Constructors
            public MultipleCondition() {
                type = MultipleConditionTypes.AND;
            }
            public MultipleCondition(MultipleConditionTypes Type){
                type = Type;
            }
        #endregion
        #region Base Implementation
            public new ConditionTypes ConditionType{
                get { return ConditionTypes.Multiple; }
            }
        #endregion
    }
}